package com.hua.server.oauth.domain;

import com.hua.server.oauth.entity.User;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.Optional;

public interface UserRepository extends JpaRepository<User,Integer>, QuerydslPredicateExecutor<User> {

    /**
     * 根据用户名获取一个对象
     *
     * @param username 用户名
     * @return User
     */
    User findByUsername(String username);

    /**
     * 根据用户id获取相关级联对象
     * @param id 用户id
     * @return User
     */
    @Override
    @EntityGraph(attributePaths = {"roles.permissions"})
    Optional<User> findById(Integer id);





}
